<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="" prop="caseName">
                    <el-input class="w-[280px]" v-model="queryParams.caseName" placeholder="案件名称"/>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table
                class="mt-4"
                size="large"
                v-loading="pager.loading"
                :data="pager.lists"
            >
                <el-table-column label="编号" prop="id" min-width="50" />
                <el-table-column label="所属归属地" prop="areaName" min-width="80" />
                <el-table-column label="所属案件" prop="caseName" min-width="100" />
                <el-table-column label="案件编号" prop="caseTradeNo" min-width="100" />
                <el-table-column label="操作" width="220" fixed="right">
                    <template #default="{ row }">
                        <el-button type="primary" link @click="handleDetail(row)">
                            查看合同
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup
            v-if="showEdit"
            ref="editRef"
            @success="getLists"
            @close="showEdit = false"
        />
    </div>
</template>
<script lang="ts" setup name="case">
import { caseDelete, caseLists, isShow } from '@/api/case'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import {useDictData} from "@/hooks/useDictOptions";
import {adminStatus} from "@/api/perms/admin";
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    caseName: '',
    status: '',
    caseType: '',
    statusArr: '',
    jumpContractSign: '1'

})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: caseLists,
    params: queryParams
})

const { dictData } = useDictData<{
    case_status1: any[],
    yes1_no0: any[],
}>(['case_status1', 'yes1_no0'])

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleDetail = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('detail')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleAudit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('audit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await caseDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

const changeStatus = async (active: any, id: number) => {
    try {
        await feedback.confirm(`确定${active ? '展示' : '不展示'}当前案件？`)
        await isShow({ id })
        feedback.msgSuccess('修改成功')
        getLists()

    } catch (error) {
        getLists()
    }
}

getLists()
</script>
